﻿using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using Ctef.Web.Models;
using System.Collections.Generic;

namespace Ctef.Web.Extensions
{
    public static class MainPageExtensions
    {
        public static MainPage Clone(this MainPage source)
        {
            if (source == null)
            {
                return null;
            }

            var result = new MainPage
            {
                Language = source.Language,
                Slider = source.Slider.DeepCopy(),
                FeaturedContent = source.FeaturedContent.DeepCopy(),
                FeaturedEvent = source.FeaturedEvent.DeepCopy(),
                FollowUs = source.FollowUs.DeepCopy(),
                Sponsors = source.Sponsors.DeepCopy(),
                Partners = source.Partners.DeepCopy()
            };

            return result;
        }

        public static T[] DeepCopy<T>(this T[] source) where T : ICloneable
        {
            if (source == null)
            {
                return null;
            }

            var len = source.Length;
            var result = new T[len];
            for (int i = 0; i < len; i++)
            {
                result[i] = (T)source[i].Clone();
            }

            return result;
        }
    }
}